package com.dexilaonian.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dexilaonian.R;
import com.dexilaonian.adpter.RecoveryAdapter;
import com.dexilaonian.fragment.GuoqiFragment;
import com.dexilaonian.fragment.WeishiyongFragment;
import com.dexilaonian.fragment.YishiyongFragment;
import com.dexilaonian.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/3/24.
 */

public class CouponActivity extends BaseActivity {
    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.base_topText)
    TextView baseTopText;
    @Bind(R.id.base_choose)
    TextView baseChoose;
    @Bind(R.id.weishiyong)
    TextView weishiyong;
    @Bind(R.id.yiyong)
    TextView yiyong;
    @Bind(R.id.guoqi)
    TextView guoqi;
    @Bind(R.id.coupon_v1)
    View couponV1;
    @Bind(R.id.coupon_v2)
    View couponV2;
    @Bind(R.id.coupon_v3)
    View couponV3;
    @Bind(R.id.coupon_viewpager)
    ViewPager couponViewpager;
    private List<Fragment> couponList = new ArrayList<>();
    private RecoveryAdapter couponAdapter;

    @Override
    public int getLayoutID() {
        return R.layout.activity_coupon;
    }

    @Override
    public void initView() {
        WeishiyongFragment weishiyong = new WeishiyongFragment();
        YishiyongFragment yishiyongFragment = new YishiyongFragment();
        GuoqiFragment guoqiFragment = new GuoqiFragment();
        couponList.add(weishiyong);
        couponList.add(yishiyongFragment);
        couponList.add(guoqiFragment);
        couponAdapter = new RecoveryAdapter(CouponActivity.this.getSupportFragmentManager(), couponList);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        baseTopText.setText("我的余额");
        couponViewpager.setAdapter(couponAdapter);
        couponViewpager.setCurrentItem(0);
        couponViewpager.setOffscreenPageLimit(3);
        couponViewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                changeTextColor(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void changeTextColor(int position) {
        if (position == 0) {
            weishiyong.setTextColor(Color.parseColor("#009a99"));
            yiyong.setTextColor(Color.parseColor("#999999"));
            guoqi.setTextColor(Color.parseColor("#999999"));
            couponV1.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
            couponV2.setBackground(null);
            couponV3.setBackground(null);

        } else if (position == 1) {
            yiyong.setTextColor(Color.parseColor("#009a99"));
            weishiyong.setTextColor(Color.parseColor("#999999"));
            guoqi.setTextColor(Color.parseColor("#999999"));
            couponV1.setBackground(null);
            couponV3.setBackground(null);
            couponV2.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
        } else if (position == 2) {
            yiyong.setTextColor(Color.parseColor("#999999"));
            weishiyong.setTextColor(Color.parseColor("#999999"));
            guoqi.setTextColor(Color.parseColor("#009a99"));
            couponV1.setBackground(null);
            couponV2.setBackground(null);
            couponV3.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
        }
    }

    @OnClick({R.id.back, R.id.base_choose, R.id.weishiyong, R.id.yiyong, R.id.guoqi})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.base_choose:
                break;
            case R.id.weishiyong:
                weishiyong.setTextColor(Color.parseColor("#009a99"));
                yiyong.setTextColor(Color.parseColor("#999999"));
                guoqi.setTextColor(Color.parseColor("#999999"));
                couponV1.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
                couponV2.setBackground(null);
                couponV3.setBackground(null);
                break;
            case R.id.yiyong:
                yiyong.setTextColor(Color.parseColor("#009a99"));
                weishiyong.setTextColor(Color.parseColor("#999999"));
                guoqi.setTextColor(Color.parseColor("#999999"));
                couponV1.setBackground(null);
                couponV3.setBackground(null);
                couponV2.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
                break;
            case R.id.guoqi:
                yiyong.setTextColor(Color.parseColor("#999999"));
                weishiyong.setTextColor(Color.parseColor("#999999"));
                guoqi.setTextColor(Color.parseColor("#009a99"));
                couponV1.setBackground(null);
                couponV2.setBackground(null);
                couponV3.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
                break;
        }
    }
}
